package com.rc.web.controller;

import com.mybatisflex.core.paginate.Page;
import com.rc.pojo.dto.knowLedgvideo.KnowLedgeVideoAddDTO;
import com.rc.pojo.dto.knowLedgvideo.KnowLedgeVideoUpdateDTO;
import com.rc.pojo.dto.knowLedgvideo.KnowledgeVideoPageQuery;
import com.rc.pojo.vo.knowledgevideo.KnowledgeVideoPageVO;
import com.rc.pojo.vo.knowledgevideo.KnowledgeVideoVO;
import com.rc.web.service.KnowledgeVideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 员工信息 控制层。
 *
 * @author sym
 * @since 2024-05-24
 */
@Api(tags = "科普视频")
@RestController
@RequestMapping("/knowledgeVideo")
@RequiredArgsConstructor
public class KnowledgeVideoController {
    private final KnowledgeVideoService videoService;

    @PostMapping
    @ApiOperation("新增")
    public void add(@RequestBody @Validated KnowLedgeVideoAddDTO dto){
        videoService.add(dto);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除")
    public void deleteById(@PathVariable Long id){
        videoService.deleteById(id);
    }

    @PutMapping
    @ApiOperation("修改")
    public void updateOneById(@RequestBody @Validated KnowLedgeVideoUpdateDTO dto){
        videoService.updateOneById(dto);
    }

    @GetMapping("/{id}")
    @ApiOperation("农场管理员查看科普详情")
    public KnowledgeVideoVO getOneById(@PathVariable Long id){
        return videoService.getOneById(id);
    }

    @GetMapping("/ill")
    @ApiOperation("通过病虫害id获取科普视频列表")
    public List<KnowledgeVideoVO> getOneByIllId(@NotNull Long illId){
        return videoService.getByIllId(illId);
    }

    @GetMapping("/page")
    @ApiOperation("农场管理员分页查看科普")
    public Page<KnowledgeVideoPageVO> getPage(KnowledgeVideoPageQuery query) {
        return videoService.getPage(query);
    }

}
